import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:kunlun_gas/app_files.dart';

class OrderPayTypeModel {
  final String typeID;
  final String typeName;

  const OrderPayTypeModel({this.typeID, this.typeName});

  @override
  bool operator ==(other) {
    if (other.runtimeType != runtimeType) return false;
    final OrderPayTypeModel typedOther = other;
    return typedOther.typeID == typeID && typedOther.typeName == typeName;
  }

  @override
  int get hashCode => typeID.hashCode ^ typeName.hashCode;
}

class InstallDetailModel {
  final String name;
  final String phone;
  final String address;
  final String idCard;
  final String payType;
  final String money;
  final String communityName;
  final List<OrderPayTypeModel> payList;

  const InstallDetailModel({
    this.name = '',
    this.phone = '',
    this.address = '',
    this.idCard = '',
    this.payType = '',
    this.money = '',
    this.communityName = '',
    this.payList,
  });

  static fromJson(var json, List<OrderPayTypeModel> payList) {
    return InstallDetailModel(
      name: CommonUtils.checkNullToString(json['OtherpayUsername']),
      phone: CommonUtils.checkNullToString(json['OtherpayUsermobile']),
      address: CommonUtils.checkNullToString(json['OtherpayUserAddress']),
      idCard: CommonUtils.checkNullToString(json['OtherpayUserIDCard']),
      payType: CommonUtils.checkNullToString(json['OtherpayPaytype']),
      money: CommonUtils.checkNullToString(json['OtherpayPayment']),
      communityName: CommonUtils.checkNullToString(json['OtherpayInCommunity']),
      payList: payList,
    );
  }

  List<String> getValueList() {
    String payName = '';
    for (OrderPayTypeModel model in payList) {
      if (model.typeID == payType)
        payName = model.typeName;
    }
    return [
      name,
      phone,
      communityName,
      address,
      idCard,
      payName,
      money,
    ];
  }
}

class InstallViewState implements Cloneable<InstallViewState> {
  String itemID;

  InstallDetailModel model;

  bool get isDetail => itemID != null;

  List orderPhoto = [];
  List<OrderPayTypeModel> payList;

  TextEditingController nameTextController = TextEditingController();
  TextEditingController phoneTextController = TextEditingController();
  TextEditingController addressTextController = TextEditingController();
  TextEditingController idCardTextController = TextEditingController();
  TextEditingController moneyTextController = TextEditingController();
  OrderPayTypeModel payTay;

  CommunityModel communityInfo;

  @override
  InstallViewState clone() {
    return InstallViewState()
      ..itemID = itemID
      ..orderPhoto = orderPhoto
      ..model = model
      ..payList = payList
      ..nameTextController = nameTextController
      ..phoneTextController = phoneTextController
      ..addressTextController = addressTextController
      ..idCardTextController = idCardTextController
      ..moneyTextController = moneyTextController
      ..payTay = payTay
      ..communityInfo = communityInfo;
  }
}

InstallViewState initState(Map<String, dynamic> args) {
  return InstallViewState()..itemID = args == null ? null : args['itemID'];
}
